from django.db import models

# Create your models here.
from django.db.models import SET_NULL, DateField, ManyToManyField, ForeignKey

from Final_Project.Tools import get_dict


class Car(models.Model):
    CarID = models.CharField(max_length=20, primary_key=True, blank=True)
    CarType = models.CharField(max_length=20, blank=True)
    CarLifeSpan = models.IntegerField(blank=True)
    ManagerID = models.CharField(max_length=20, null=True, blank=True)
    StopServeDate = models.DateField(null=True, blank=True)
    StopUseReason = models.TextField(null=True, blank=True)
    UsingDate = models.DateField(blank=True)
    CarCategory = models.CharField(max_length=5, blank=True)
    PassengerNum = models.IntegerField(blank=True)
    WorkingState = models.CharField(max_length=5, default="可用", blank=True)

    def to_dict(self, fields=None, exclude=None):
        return get_dict(self, fields, exclude)


class Repair(models.Model):
    Car = models.ForeignKey(to=Car, on_delete=models.CASCADE, blank=True)
    StartTime = models.DateField(blank=True)
    Reason = models.TextField(null=True, blank=True)
    EndTime = models.DateField(null=True, blank=True)

    def to_dict(self, fields=None, exclude=None):
        return get_dict(self, fields, exclude)

